package com.daylive.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.daylive.model.SysLog;
import com.daylive.page.Page;
import com.daylive.service.LogService;


@Controller
@RequestMapping("log")
public class LogController {
	
	@Autowired
	private LogService  logService;
	public static HttpSession getSession() {
		HttpSession session = null;
		try {
			session = getRequest().getSession();
		} catch (Exception e) {
		}
		return session;
	}

	public static HttpServletRequest getRequest() {
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		return attrs.getRequest();
	}
	private void clearSession() {
		getSession().invalidate();
	}

	@RequestMapping("/log_list.do")
	public ModelAndView getLogList() {
		return getLogList(1);
	}
	@RequestMapping("/log_page_list.do")
	public ModelAndView getLogList(@RequestParam int pageNumber) {
		Page<SysLog> pageList = logService.getSysLogList(pageNumber);
		ModelAndView mv = new ModelAndView("log_list");
		mv.addObject("currentPage", pageNumber);
		mv.addObject("totalPage", pageList.getTotalPage());
		mv.addObject("totalCount", pageList.getTotalCount());
		mv.addObject("logList", pageList.getResultList());
		return mv;
	}
	    @RequestMapping("/log_del.do")
		public String deleteLog(@RequestParam("id")int id) {
			logService.delSysLog(id);
			return "success";
		}
	    
		@RequestMapping("/user_delAll.do")
		public String deleteAll(String ids) {
			String[] array_IDS = ids.split(",");
			logService.delAll(array_IDS);
			return "success";
		}
}